import {
	// 创建路由api
	createRouter,
	// 创建路由历史模式
	createWebHashHistory
} from "vue-router"

const routes = [
	{
		path:"/",
		redirect:"/login"
	},
	{
		name:"login",
		path:"/login",
		component:()=>import("@/views/login/index.vue")
	},
	{
		name:"menu",
		path:"/menu",
		component:()=>import("@/views/menu/index.vue"),
		children:[
			{
				name:"home",
				path:"/home",
				component:()=>import("@/views/home/index.vue")
			},
			{
				name:"set",
				path:"/set",
				component:()=>import("@/views/set/index.vue")
			},
			{
				name:"overview",
				path:"/overview",
				component:()=>import("@/views/overview/index.vue")
			},
			{
				name:"message_manage",
				path:"/message_manage",
				component:()=>import("@/views/user_manage/message_manage/index.vue")
			},
			{
				name:"product_manage",
				path:"/product_manage",
				component:()=>import("@/views/user_manage/product_manage/index.vue")
			},
			{
				name:"user_list",
				path:"/user_list",
				component:()=>import("@/views/user_manage/user_list/index.vue")
			},
			{
				name:"users_manage",
				path:"/users_manage",
				component:()=>import("@/views/user_manage/users_manage/index.vue")
			}
		]
	}
]



const router = createRouter({
	history:createWebHashHistory(),
	routes
})
// 设置前置守卫
router.beforeEach((to,form,next)=>{
	const token = localStorage.getItem("token")
	if(to.name !== 'login' && !token) next({name:'login'})
	else next()
})
export default router